package com.ly.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.CourseBaseDto;
import com.ly.cloud.service.CourseManageService;
import com.ly.cloud.vo.CourseBaseVo;
import com.ly.cloud.web.utils.WebResponse;

/**
 * 课程维护Controller
 * @author caihuihai
 * @date 2018年12月18日 下午8:21:52
 */
@RestController
@RequestMapping("/courseManage")
public class CourseManageController {
	
	@Autowired
    private CourseManageService manageService ;
	
	/**
	 * 分页查询课程库基本信息列表
	 * @return
	 */
	@RequestMapping(value = "/queryList", method = RequestMethod.GET)
	public WebResponse<PageInfo<CourseBaseVo>> queryPageList(@RequestParam int pageNum, @RequestParam int pageSize,CourseBaseDto dto) {
		Page<CourseBaseVo> page = manageService.selectPage(new Page<CourseBaseVo>(pageNum, pageSize),dto);
		return new WebResponse<PageInfo<CourseBaseVo>>().success(PageInfo.toPageInfo(page));
	}
	
	/**
	 * 根据课程编号查询课程信息（包括学时、项目）
	 * @param kch 课程编号
	 * @return
	 */
    @RequestMapping(value = "/findKcxxByKch", method = RequestMethod.GET)
    public WebResponse<CourseBaseVo> findTeachList(@RequestParam String kch){
    	CourseBaseVo vo = manageService.findKcxxByKch(kch);
        return new WebResponse<CourseBaseVo>().success(vo) ;
    }
    
	
	/**
	 * 提交课程基本信息（新增、修改）
	 * @param loginUserName
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/submitKc", method = RequestMethod.POST)
	public WebResponse<Boolean> submitKc(@RequestHeader(required=false,value="loginUserName")String loginUserName,@RequestBody CourseBaseDto dto) {
		boolean rs = manageService.submitKc(dto,loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 删除课程的项目信息
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/deleteKcxm/{kch}/{xmbh}", method = RequestMethod.POST)
	public WebResponse<Boolean> deleteKcxm(@PathVariable("kch") String kch,@PathVariable("xmbh") String xmbh) {
		boolean rs = manageService.deleteKcxm(kch,xmbh);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 批量删除课程
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/batchDelKc", method = RequestMethod.POST)
	public WebResponse<Boolean> batchDelKc(@RequestBody List<String> kchs) {
		boolean rs = manageService.batchDelKc(kchs);
		return new WebResponse<Boolean>().success(rs);
	}
	

}
